/**
 * 功能描述 列表
 */

define(function (require, exports, module){
	var EditGrid = require("editgrid");
	var enmu=require("enums");
	
	var instance = {
		initComponent:function (params,widget){
			var alltotalGrid = new EditGrid({
				parentNode:".J-alltotal",
				autoRender : false,
				model:{
					id:"total",
					isInitPageBar: false,
					allowAdd: false,
					columns:[{
						name: "allianceChargesTotal",
						label: "联盟酒店费用合计",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name: "manageChargesTotal",
						label: "组团管理费合计",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"otherChargesTotal",
						label:"其他费用合计",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"allTotal",
						label:"费用总金额",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"depositTotal",
						label:"预收款合计",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"deductionChargesTotal",
						label:"权证抵扣合计",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"receivableTotal",
						label:"应收金额合计",
						format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"receiptsTotal",
						label:"实收金额合计",
						editor:{
							type:"text",
							onChange:function(plugin,index,rowData){
								rowData.receiptsTotal=parseFloat(plugin.getValue());
								totalGrid.update(index,rowData);
							}
						},
						format: function(value, data) {
    		            	if(!isNaN(value)){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
					},{
						name:"paymentMethod",
						label:"结算方式",
						format : function(value, row) {
							var arr = [];
							if(value.length>0){
								for(var i=0;i<value.length;i++){
									arr.push(value[i].value);
								}
							}
							
							return arr.join(",");
		    			},
						editor:{
							type:"select",
							multi : true,
							options:[{
								key:"Cash",
								value:"现金"
							},{
								key:"WipeCard",
								value:"刷卡"
							},{
								key:"Transfer",
								value:"转账"
							},{
								key:"OnCredit",
								value:"挂账"
							}],
							onEdit:function(plugin,index,rowData){
								var paymentMethod = rowData.paymentMethod;
								var vals = [];
								for(var i = 0 ; i<paymentMethod.length; i++){
									vals[i] = paymentMethod[i].key;
								}
								plugin.setValue(vals);
							},
							onChange:function(plugin,index,rowData){
								var paymentMethod = [];
								var paymentMethodValue = plugin.getValue();
								for(var i = 0; i < paymentMethodValue.length; i++){
									paymentMethod[i] = plugin.getData(paymentMethodValue[i]);
								}
								rowData.paymentMethod = paymentMethod;
								alltotalGrid.update(index,rowData);
							}
						},
					},{
						name:"description",
						label:"备注",
						editor:{
							type:"text",
							onChange:function(plugin,index,rowData){
								rowData.description=plugin.getValue();
								alltotalGrid.update(index,rowData);
							}
						}
					}]
				}
			});
			widget.set("alltotalGrid",alltotalGrid);
		}
	};
	module.exports = instance;
});
